#
#   Enemy.py
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; version 2 of the License.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   Copyright
#   Author: Nicholas F. Hoover
#   Contributors: 
#   Created: 2007.06.25
#   Last Modified: 2007.07.08
#

from Character import Character


class Enemy(Character):

    TARGET_REACHED_X_RANGE = 5
    TARGET_REACHED_Y_RANGE = 4

    AUTO_Y_ADJUST = 2

    def __init__(self):
        Character.__init__(self)


    #Name: moveTowardTarget
    #Description: Directs an Enemy toward the closest side of the targetRect and the bottom
    def moveTowardTarget(self, targetRect):
        inXRange = False
        inYRange = False
        if self.rect.right < targetRect.centerx - Enemy.TARGET_REACHED_X_RANGE:
            self.currentAnimation = self.RUN_SIDE
            self.facing = self.RIGHT
        elif self.rect.left > targetRect.centerx + Enemy.TARGET_REACHED_X_RANGE:
            self.currentAnimation = self.RUN_SIDE + self.LEFT
            self.facing = self.LEFT
        else:
            inXRange = True


        if self.rect.bottom < targetRect.bottom - Enemy.TARGET_REACHED_Y_RANGE:
            self.rect.top += Enemy.AUTO_Y_ADJUST
        elif self.rect.bottom > targetRect.bottom + Enemy.TARGET_REACHED_Y_RANGE:
            self.rect.top -= Enemy.AUTO_Y_ADJUST
        else: inYRange = True

        return inXRange and inYRange
            
